#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 1010;
char mp[maxn][maxn];
string word[maxn];
int t, l, c, w;
struct Trie {
    int fail, id;
    bool flag;
    int son[26];
}a[maxn * maxn];
// 上	右上	右	右下	下	左下	左	左上
//  0    1      2    3      4   5       6   7
//  A    B      C    D      E   F       G   H
const int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int cnt;
int ox[maxn], oy[maxn], ok[maxn];
bool vis[maxn];
void inrt(string s, int id) {
    int now = 0;
    for (int i = 0; i < s.length(); i++) {
        if (a[now].son[s[i] - 'A'] == 0) {
            a[now].son[s[i] - 'A'] = ++ cnt;
        }
        now = a[now].son[s[i] - 'A'];
    }
    a[now].id = id;
}
void bfail() {
    queue<int> q;
    for (int i = 0; i < 26; i++) {
        if (a[0].son[i]) {
            a[a[0].son[i]].fail = 0;
            q.push(a[0].son[i]);
        }
    }
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (int i = 0; i < 26; i++) {
            if (a[u].son[i]) {
                a[a[u].son[i]].fail = a[a[u].fail].son[i];
                q.push(a[u].son[i]);
            }
            else {
                a[u].son[i] = a[a[u].fail].son[i];
            }
        }
    }
}
void query(int sx, int sy, int k) {
    // if (k == 2) cout << "entering " << sx << " " << sy << " " << k << endl;
    int nx = sx, ny = sy;
    int now = 0;
    while (nx >= 1 && nx <= l && ny >= 1 && ny <= c) {
        now = a[now].son[mp[nx][ny] - 'A'];
        int p = now;
        // if (k == 2) cout << nx << " " << ny << " now:" << now << endl;
        while (p != 0) {
            // if (a[p].id && !a[p].flag) {
            if (a[p].id && !vis[a[p].id]) {
                // a[p].flag = true;
                vis[a[p].id] = true;
                int rx = nx - (word[a[now].id].length() - 1) * dx[k];
                int ry = ny - (word[a[now].id].length() - 1) * dy[k];
                ox[a[now].id] = rx; oy[a[now].id] = ry;
                ok[a[now].id] = k;
            }
            p = a[p].fail;
        }
        // if (!a[now].flag) {
            // cout << sx << " " << sy << " " << nx << " " << ny << " " << k << endl;
            // calc the start point (rx, ry)
            // int rx = nx - (word[a[now].id].length() - 1) * dx[k];
            // int ry = ny - (word[a[now].id].length() - 1) * dy[k];
            // ox[a[now].id] = rx; oy[a[now].id] = ry;
            // ok[a[now].id] = k;
            // a[now].flag = true;
        // }
        nx += dx[k]; ny += dy[k];
    }
}
void print() {
    for (int i = 1; i <= w; i++) {
        cout << ox[i] - 1 << " " << oy[i] - 1<< " " << char(ok[i] + 'A') << endl;
    }
}
void clear() {
    memset(a, 0, sizeof a);
    cnt = 0;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> t;
    for (int _ = 1; _ <= t; _++) {
        clear();
        cin >> l >> c >> w;
        for (int i = 1; i <= l; i++) {
            for (int j = 1; j <= c; j++) {
                cin >> mp[i][j];
            }
        }
        for (int i = 1; i <= w; i++) {
            cin >> word[i];
            inrt(word[i], i);
        }
        bfail();
        
        // normal -> 0, 4
        for (int i = 1; i <= c; i++) {
            query(1, i, 4); query(l, i, 0);
        }
        // normal -> 2, 6
        for (int i = 1; i <= l; i++) {
            query(i, 1, 2); query(i, c, 6);
        }
        //        -> 3, 7
        for (int i = 1; i <= l; i++) {
            query(i, 1, 3); query(i, c, 7);
        }
        for (int i = 1; i <= c; i++) {
            query(1, i, 3); query(l, i, 7);
        }
        //        -> 1, 5;
        for (int i = 1; i <= l; i++) {
            query(i, 1, 1); query(i, c, 5);
        }
        for (int i = 1; i <= c; i++) {
            query(1, i, 5); query(l, i, 1);
        }
        /*
        for (int i = 1; i <= c; i++)
            for (int k = 0; k < 8; k++) query(i, 0, k);
        for (int i = 1; i <= c; i++)
            for (int k = 0; k < 8; k++) query(i, c - 1, k);
        for (int i = 1; i <= l; i++)
            for (int k = 0; k < 8; k++) query(0, i, k);
        for (int i = 1; i <= l; i++)
            for (int k = 0; k < 8; k++) query(l - 1, i, k);
        */
        // output
        print();
    }
    return 0;
}
